<?php
// 本类由系统自动生成，仅供测试用途
class ArticleAction extends BaseAction {
    public function __construct() {
        parent::__construct();
        //权限判定
        
        //语言包设置
        $language['ch']=array(
            //头部
            "titlebt"=>'文章管理',
            "now_path"=>'当前位置',
            "header_admin"=>"文章管理",
            "header_add"=>"添加文章",
            "header_value1"=>"在这里，你可以设置",
            "header_value2"=>"文章",
            "header_value3"=>"其他3",
            "header_value4"=>"其他4",
            "header_value5"=>"其他5",
            "header_value6"=>"其他6",
            "titlebt2"=>"栏目",
        );
        
        //解析语言包
        $this->assign("language",$language['ch']);
        
        
    }
    public function index(){
        $array=array();
        $where=array();
        if(isset($_GET['sid'])&&  intval($_GET['sid'])>0){
            $this->assign("sid",  intval($_GET['sid']));
            $array['sid']=  intval($_GET['sid']);
            $where[C("DB_PREFIX").'article.article_sort_id']=intval($_GET['sid']);
        }
        
        $article=D("Article");
        $sort=D("ArticleSort");
        $articlesort=$sort
                ->order("article_sort_path")
                ->select();
        $maxlevel=1;
        foreach($articlesort as $key=>$vo){
            $num=substr_count($vo['article_sort_path'],',');
            $articlesort[$key]['level']=$num-1;
            if($maxlevel<$num-1){
                $maxlevel=$num-1;
            }
        }
        $articlesort[0]['maxlevel']=$maxlevel;
        //print_r($articlesort);
        $this->assign("sort",$articlesort);
        //分页
        $page=  page(10, $article, $where, $array);
        $this->assign("page",$page);
        $list=$article
            ->join(C("DB_PREFIX")."article_sort sort ON sort.article_sort_id=".C("DB_PREFIX")."article.article_sort_id")
                ->where($where)
            ->order("article_id desc")
                ->limit("{$page['start']},{$page['number']}")
                ->select();
        
        $this->assign("article",$list);
        $this->display();
    }
    
    public function insert(){
        $model=D("model");
        $name['title']=$model
                    ->where(array("model_parent_id"=>0))
                    ->order("model_order")
                    ->select();
        if(isset($_GET['sid'])&&  intval($_GET['sid'])>0){
            $this->assign("sid",intval($_GET['sid']));
        }
        $this->assign("models",$name);
        $this->display();
    }
    
    public function update(){
        if(isset($_GET['sid'])&&  intval($_GET['sid'])>0){
            $sid=intval($_GET['sid']);
            $model=D("model");
            $name['title']=$model
                    ->where(array("model_parent_id"=>0))
                    ->order("model_order")
                    ->select();
            //echo $model->getLastSql();
            $model_this=$model
                        ->where(array("model_id"=>$sid))
                        ->find();
            //echo $sid;
            //echo $model->getLastSql();
                $this->assign("models",$name);
                $this->assign("model_this",$model_this);
            $this->display();
        }else{
            $this->error("数据错误");
        }
        
    }
    
    public function del(){
        if(isset($_GET['sid'])&&  intval($_GET['sid'])>0){
            $sid=intval($_GET['sid']);
            $model=D("model");
            $del=$model
                ->where(array("model_id"=>$sid))
                ->delete();
            if($del){
                $this->success("删除成功");
                
            }else{
                $this->error("删除失败");
            }
        }else{
            $this->error("数据错误");
        }
    }
    
}